﻿
@{
    ViewData["Title"] = "WarehouseIndex";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="/libs/layui@2.9.21/dist/css/layui.css" rel="stylesheet">
    <link href="~/lib/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layer/skin/layer.css" rel="stylesheet" />


</head>
<body>


    @* 查询条件 *@
    <form class="layui-form layui-row layui-col-space16">
        <div class="layui-col-sm3">
            <input type="text" name="snName" placeholder="产品物料名称" class="layui-input">
        </div>

        <button type="button" class="layui-btn layui-bg-blue">查询</button>
        <button type="button" class="layui-btn">重置</button>

        <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-custom" onclick="addReturn()">
            新增
        </button>

    </form>





    @* 显示数据表格 *@
    <table class="layui-hide" id="wareHouse" lay-filter="wareHouse" style="margin-top: 20px;margin-left: 20px">
    </table>


    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="upd">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
    </script>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/lib/layui/layui.js"></script>

    <script src="~/layer/layer.js"></script>

</body>
</html>

<script>

    layui.use('table', function () {
       var table = layui.table;
       var form = layui.form;
       var laydate = layui.laydate;

           table.render({
           elem: '#wareHouse',
           url: '/Warehouse/GetSNDataList', // 实际接口地址
           page: true, // 开启分页
           limit: 10, // 每页默认显示的条数
           limits: [10, 20, 30], // 每页条数的选择项
           cols: [
               [
                  { field: 'snCode', title: '产品编码', width: 120,id:'snCode' },
                  { field: 'snName', title: '产品名称', width: 120,id:'snName' },
                  { field: 'models', title: '规格型号' , width: 120,id:'models' },
                  { field: 'unit', title: '单位' , width: 120,id:'unit' },
  
                   { field: 'batchCode', title: '批次号' , width: 120,id:'batchCode' },
                    { field: 'snNum', title: 'SN码数量' , width: 120,id:'snNum' },

                 

                   { title: '操作', fixed: 'right', width: 200, align: 'center', toolbar: '#barDemo' }
               ]
          ],
          parseData: function (res) {
              return {
                  code: res.code,
                  count: res.total,
                  data: res.data
              };
          },
           })

              table.on('tool(wareHouse)', function(obj) {
        var data = obj.data;//获取当前行数据
        console.log(data,"当前行数据");


        if (obj.event === 'delete') {
            //在这里进行删除操作
        console.log("获取到的 ID:",data.id);
        layer.confirm('确定要删除吗？', {
             btn: ['确定', '取消'] //按钮
         }, function () {
             $.ajax({
                 url: '/Warehouse/SNDataDelete',
                 type: 'post',
                 data: {
                   id: data.id
                },
                 success: function (res) {
                     console.log(res);
                     if (res.msg == '删除成功') {
                         layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                             location.reload(); //刷新页面
                         });
                     } else {
                         layer.msg(res.msg, { icon: 2, time: 1000 });
                     }
                 }
             });
         }, function () {
             layer.msg('已取消', { icon: 1, time: 1000 });
         });
        }

        if(obj.event === 'upd'){
         console.log(data.id);
          //iframe层
       layer.open({
           type: 2,
           title: '修改客户数据',
           shadeClose: true,
           shade: 0.5,
           area: ['600px', '60%'],
           content: '/Warehouse/UpdateCustomerDatatView?id='+ data.id, //iframe的src
           end: function () {
               // iframe层关闭后刷新页面
               location.reload(); // 刷新页面
           }
       });
        }

    });

    });

      //添加
     function addReturn() {
         console.log("添加客户数据");
          //iframe层
       layer.open({
           type: 2,
           title: '添加客户数据',
           shadeClose: true,
           shade: 0.5,
           area: ['800px', '100%'],
           content: '/Warehouse/WarehouseAddIndex', //iframe的src
           end: function () {
               // iframe层关闭后刷新页面
               location.reload(); // 刷新页面
           }
       });
     }

        //删除



</script>


